home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Prog / M / MPWGCC (Machines).cpt / Miscellaneous / masm386.c < prev    next >
Encoding:
Text File  |  1990-02-21  |  5.6 KB  |  226 lines  |  [TEXT/MPS ]

  1. /* Subroutines for insn-output.c for Intel 80386 for masm assembler syntax.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.   
  21. FILE *aux_asm_out_file;
  22.  
  23. static tree *implicit_declares;
  24. int implicit_declares_max = 0;
  25. int implicit_declares_fillp = 0;
  26.  
  27.  
  28. add_to_implicit_list (t)
  29.      tree t;
  30.   if (implicit_declares_max > implicit_declares_fillp)
  31.     {
  32.       implicit_declares[implicit_declares_fillp++] = t;
  33.     }
  34.   else
  35.     {
  36.       tree *new;
  37.       int i;
  38.  
  39.       implicit_declares_max = 2 * (implicit_declares_max + 10);
  40.       new = (tree *)(xmalloc (implicit_declares_max * sizeof (tree *)));
  41.       for (i = 0; i < implicit_declares_fillp; i++)
  42.     new[i] = implicit_declares[i];
  43.       implicit_declares = new;
  44.       implicit_declares[implicit_declares_fillp++] = t;
  45.     }
  46. }
  47.  
  48.  
  49. write_implicit_declares ()
  50. {
  51.   int i;
  52.   for (i = 0; i < implicit_declares_fillp; i++)
  53.     {
  54.       tree t;
  55.       t = implicit_declares[i];
  56.       if (!IDENTIFIER_GLOBAL_VALUE (t) && IDENTIFIER_IMPLICIT_DECL (t))
  57.     {            /* avoid repeats */
  58.       IDENTIFIER_IMPLICIT_DECL (t) = 0;
  59.       fprintf (aux_asm_out_file, "EXTRN ");
  60.       assemble_name (aux_asm_out_file, IDENTIFIER_POINTER (t));
  61.       fprintf (aux_asm_out_file, ":NEAR ; implicit\n");
  62.     }
  63.     }
  64. }
  65.       
  66.  
  67. void
  68. asm_write_decls (decls, toplevel)
  69.      int toplevel;     
  70.      tree decls;     
  71. {
  72.   tree tr, t;
  73.   char *type, *size;
  74.   tr = nreverse (decls);
  75.   for (t = tr; t; t = TREE_CHAIN (t))
  76.     { 
  77.       type = 0;
  78.       size = 0;
  79.       if (TREE_CODE (t) == FUNCTION_DECL
  80.       && (!toplevel || TREE_ASM_WRITTEN (t)))
  81.     {
  82.       if (!toplevel && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (t)))
  83.         { 
  84.           add_to_implicit_list (DECL_NAME (t));
  85.           continue;
  86.         }
  87.       if (TREE_PUBLIC (t)
  88.           && (DECL_INITIAL (t)))
  89.         type = "PUBLIC "; 
  90.       else {
  91.         if (TREE_PUBLIC (t) || TREE_EXTERNAL (t))
  92.           {
  93.         type = "EXTRN ";
  94.         size = "NEAR";
  95.           }
  96.       }
  97.     }
  98.       else
  99.     if (TREE_CODE (t) == VAR_DECL)
  100.       {
  101.         if (TREE_PUBLIC (t) && DECL_INITIAL (t))
  102.           type = "PUBLIC ";
  103.         else if (TREE_EXTERNAL (t))
  104.           {
  105.         type = "EXTRN ";
  106.         switch (int_size_in_bytes (TREE_TYPE (t)))
  107.           {
  108.           case 1: size = "BYTE"; break;
  109.           case 2: size = "WORD"; break;
  110.           case 4: size = "DWORD"; break;
  111.           case 8: size = "QWORD"; break;
  112.           default: size = "BYTE"; break;
  113.           }
  114.           }
  115.       }
  116.       if (type)
  117.     { 
  118.       fputs (type, aux_asm_out_file);
  119.       putc (' ', aux_asm_out_file);
  120.       assemble_name (aux_asm_out_file, IDENTIFIER_POINTER (DECL_NAME (t)));
  121.       if (size)
  122.         fprintf (aux_asm_out_file, ":%s", size);
  123.       fprintf (aux_asm_out_file, "\t\t; %d,%d,%d,%d,%d",
  124.            TREE_EXTERNAL (t), TREE_PUBLIC (t), TREE_STATIC (t),
  125.            DECL_INITIAL (t), TREE_CODE (t));
  126.       putc ('\n', aux_asm_out_file);
  127.     }
  128.     }
  129.   nreverse (tr);
  130. }
  131.  
  132. /*  If we are using a library which does not follow the underscore convention,
  133. (which is absolutely necessary for masm, since it has hundreds of reserved
  134.  words), we do not put an underscore in front of the following names.
  135. It was produced by having a foo /tmp/foo.c which included standard library h
  136.   files, and then using
  137.   cat /tmp/foo.m | sed -e 's/EXTRN  /"/g' -e 's/:[a-zA-Z]+/",/g'  | sort > masm-lib.h
  138. It will be nice when we have our own libraries!
  139.  */
  140.  
  141. /* #include <string.h> */
  142.  
  143. char *no_prefix_names[] = {
  144. #include "masm-lib.h"
  145. };
  146.  
  147. static int
  148. node_compare (a, b)
  149.      char **a, **b;
  150. {
  151.   return strcmp (*a, *b);
  152. }
  153.  
  154. /*  Masm needs extrn references for ALL symbols written,
  155.     unless they are defined in this file.  However unnecessary extrn
  156.     references to functions, cause their code to be linked in.
  157.     To avoid this we mark function declarations whose names have been
  158.     written.
  159.     Make local varialbes
  160.     */
  161.  
  162. void
  163. mark_name_used (name)
  164.      char *name;
  165. {
  166.   tree t = get_identifier (name);
  167.   if (IDENTIFIER_GLOBAL_VALUE (t)
  168.       && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (t)) == FUNCTION_DECL)
  169.     TREE_ASM_WRITTEN (IDENTIFIER_GLOBAL_VALUE (t)) = 1;
  170. }
  171.  
  172. static int number_no_prefix_names = 0;
  173. int use_prefix = 1;
  174.  
  175. asm_output_labelref (file, name)
  176.      int file;
  177.      char *name;
  178. {
  179.   int i;
  180.   char *ans;
  181.   char *test[1];
  182.  
  183.   mark_name_used (name);
  184.   ans = 0;
  185.   test[0] = name;
  186.   if (!number_no_prefix_names)
  187.     {
  188.       for (i = 0;; i++)
  189.     if (*(no_prefix_names[i]) == 0)
  190.       {
  191.         number_no_prefix_names = i;
  192.         break;
  193.       }
  194.     }
  195.   if (use_prefix)
  196.     ans = 
  197.       (char *)
  198.     bsearch (test, no_prefix_names, number_no_prefix_names,
  199.          sizeof (char *), node_compare);
  200.   if (ans || !use_prefix)
  201.     fprintf (file, name);
  202.   else
  203.     fprintf (file, "_%s", name);
  204. }
  205.  
  206. void 
  207. asm_library_declare (fun)
  208.      rtx fun;     
  209. {
  210.   tree iden; 
  211.   iden = get_identifier (XSTR (fun, 0));
  212.   if (!TREE_ASM_WRITTEN (iden)) 
  213.     {
  214.       fprintf (aux_asm_out_file, "EXTRN "); 
  215.       assemble_name (aux_asm_out_file, XSTR (fun, 0)); 
  216.       fprintf (aux_asm_out_file, ":NEAR ; library\n"); 
  217.       TREE_ASM_WRITTEN (iden) = 1;
  218.     }
  219. }
  220.  
  221. /* list of implicit declares identifier_node uid's
  222.    We must track implicit declares, since we cannot call them extern,
  223.    until we are sure they will not be static defined in this file.
  224.  */
  225.